package com.xiake.service.impl.user;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiake.core.entity.user.UserInfo;
import com.xiake.core.model.AppUserInfo;
import com.xiake.dao.user.UserInfoDao;
import com.xiake.dao.user.impl.UserInfoDaoImpl;
import com.xiake.service.impl.base.BaseServiceImpl;
import com.xiake.service.user.UserInfoService;
@Service
public class UserInfoServiceImpl extends BaseServiceImpl<UserInfo, Integer> implements
		UserInfoService {
	@Autowired
	private UserInfoDao userInfoDao;
	
	public UserInfoServiceImpl(){
		super(new UserInfoDaoImpl(UserInfo.class));
	}

	@Override
	public AppUserInfo getAppUserInfoByToken(String token) throws Exception {
		token = token.replace(" ", "+");
		AppUserInfo appUser = null;
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		sqlMap.put("token", token);
		UserInfo userInfo = this.get(sqlMap, "ByToken");
		if(userInfo != null){
			appUser = new AppUserInfo();
			BeanUtils.copyProperties(userInfo, appUser);
		}
		return appUser;
	}

}
